<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>回调</title>

    <!--集成vue和axios，还要axios全局配置（导入common.js）-->
    <!--script src方式引入vue和axios-->
    <script src="js/plugins/vue/dist/vue.js"></script>
    <script src="js/plugins/axios/dist/axios.js"></script>
    <!--全局配置，以后只要用vue+axios的页面都引入common.js-->
    <script src="js/common.js"></script>
</head>
<body>
    <div id="myDiv">

    </div>
    <script type="text/javascript">
        new Vue({
            el:"#myDiv",
            mounted(){
                //解析参数对象
                let url = location.href;
                let paramObj = parseUrlParams2Obj(url);

                //获取发送请求参数
                let binderUrl = "http://bugtracker.itsource.cn/binder.html"
                let params = {"code":paramObj.code,"binderUrl":binderUrl};

                //发起微信登录请求
                this.$http.post("/login/wechat",params)
                    .then(result=>{
                        result = result.data;
                        if(result.success){ //已经关联了
                            //做登录
                            //提示
                            alert("登录成功！")
                            //把token和loginInfo存放到localStorage
                            let {token,loginInfo} = result.resultObj;
                            localStorage.setItem("token",token);
                            //把对象转换为json字符串存放
                            localStorage.setItem("loginInfo",JSON.stringify(loginInfo));
                            //跳转主页
                            location.href = "/index.html";
                        }else{ //没有关联跳转关联页面
                            let url = result.resultObj;
                            location.href = url;
                        }
                    })
                    .catch(result=>{
                        alert("系统错误");
                        console.log(result);
                    })
            }
        });
    </script>
</body>
</html>